home *** CD-ROM | disk | FTP | other *** search
/ Over 1,000 Windows 95 Programs / Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso / 1271 / termline.bas < prev    next >
BASIC Source File  |  1997-03-18  |  5KB  |  199 lines

  1. ' TERM.BAS
  2. Option Explicit
  3.  
  4. Dim FatalFlag As Integer
  5. Dim Code As Integer
  6.  
  7. Sub Aborting ()
  8.   Dim Code As Integer
  9.   TERM.Print "Fatal Error, Aborting..."
  10.   Code = SioDone(ThePort)
  11.   End
  12. End Sub
  13.  
  14. Sub GetIncoming ()
  15.   Dim i As Integer
  16.   Dim TheChar As Integer
  17.   Dim Code As Integer
  18.   Dim S As String
  19.   'is modem I/O (MIO) running ?
  20.   If mioState <> 0 Then
  21.     'run Modem I/O driver
  22.     Call RunMIO
  23.     Exit Sub
  24.   End If
  25.   'is XMODEM / YMODEM driver running ?
  26.   If xyState <> 0 Then
  27.     'run xyDriver
  28.     Call RunXY
  29.     Exit Sub
  30.   End If
  31.   'get all incoming serial
  32.   For i = 1 To 1000
  33.     TheChar = SioGetc(ThePort)
  34.     If TheChar > 0 Then
  35.       Call DisplayChar(TERM, TheChar)
  36.     Else
  37.       Exit For
  38.     End If
  39.   Next i
  40. End Sub
  41.  
  42. Sub GoOffLine ()
  43.   Dim Code As Integer
  44.   OnLineFlag = 0
  45.   'release xyDriver
  46.   Code = xyRelease(ThePort)
  47.   'shut down port
  48.   Code = SioDone(ThePort)
  49. End Sub
  50.  
  51. Sub GoOnLine ()
  52.   Dim i As Integer
  53.   Dim RxQueSize As Integer
  54.   Dim TxQueSize As Integer
  55.   If OnLineFlag Then
  56.     Exit Sub
  57.   End If
  58.   'reset the port (1024 byte RX buffer & 128 byte TX buffer)
  59.   RxQueSize = 1024
  60.   TxQueSize = 128
  61.   Code = SioReset(ThePort, RxQueSize, TxQueSize)
  62.   If Code < 0 Then
  63.     Call SayError(TERM, Code)
  64.     Exit Sub
  65.   End If
  66.   ''' set baud rate
  67.   Code = SioBaud(ThePort, TheBaudCode)
  68.   'call Aborting() if detect error after resetting port
  69.   Call DisplayLine(TERM, "COM" + LTrim$(Str$(1 + ThePort)) + " reset")
  70.   'set DTR & RTS
  71.   Code = SioDTR(ThePort, Asc("S"))
  72.   Code = SioRTS(ThePort, Asc("S"))
  73.   'turn on hardware flow control
  74.   Code = SioFlow(ThePort, Asc("H"))
  75.   Call DisplayLine(TERM,"RTS/CTS flow control on [Waiting for DSR]")
  76.   If SioCTS(ThePort) = 0 Then 
  77.     Call DisplayLine(TERM,"Flow control not enabled on modem [CTS=0]")
  78.   End If  
  79.   ' set parms
  80.   Code = SioParms(ThePort, TheParity, TheStopBits, TheDataBits)
  81.   'acquire xyDriver
  82.   Code = xyAcquire(ThePort)
  83.   'set xyDriver debug level
  84.   Code = xyDebug(DebugLevel)
  85.   ' we're online !
  86.   OnLineFlag = 1
  87. End Sub
  88.  
  89. Sub RunMIO ()
  90.   Dim i As Integer
  91.   Dim TheChar As Integer
  92.   Dim Code As Integer
  93.   Dim S As String
  94.   'MIO is running
  95.   TheChar = mioDriver(ThePort)
  96.   If TheChar = MIO_IDLE Then
  97.     'time to go to next MIO state (since driver is idle)
  98.     Select Case mioState
  99.       '*** DIAL states ***
  100.       Case Dial_1
  101.         'dial modem [edit to call local BBS]
  102.         S = "!!ATDT" + TERM.AcceptText.Text + "!"
  103.         Call DisplayLine(TERM, S)
  104.         Code = mioSendTo(ThePort, 100&, S)
  105.         mioState = Dial_2
  106.       Case Dial_2
  107.         'expect "CONNECT" back (wait up to 60 seconds)
  108.         If mioWaitFor(ThePort, 60000&, "CONNECT") Then
  109.           mioState = Dial_3
  110.         Else
  111.           'error!
  112.           Call DisplayLine(TERM, ">>>mioWaitFor fails!")
  113.           TERM.menuDial.Enabled = True
  114.           mioState = 0
  115.         End If
  116.       Case Dial_3
  117.         'did we get expected result ("CONNECT")
  118.         If mioResult(ThePort) Then
  119.           Call DisplayLine(TERM, ">>>CONNECT was received")
  120.         Else
  121.           Call DisplayLine(TERM, ">>>CONNECT was NOT received!")
  122.         End If
  123.         'all done
  124.         mioState = 0
  125.         TERM.menuBreak.Enabled = False
  126.       End Select
  127.     Else
  128.       'MIO is not IDLE (it's running)
  129.       If TheChar <> MIO_RUNNING Then
  130.         Call DisplayChar(TERM, TheChar)
  131.       End If
  132.     End If
  133. End Sub
  134.  
  135. Sub RunXY ()
  136.   Dim Code As Integer
  137.   Dim Buffer As String * 81
  138.   Dim Text As String
  139.   Dim Packet As Integer
  140.   ' any messages from xyDriver ?
  141.   While xyGetMessage(Buffer, 80) > 0
  142.     Text = Buffer
  143.     Call DisplayLine(TERM, Text)
  144.   Wend
  145.   ' run the driver                                                 n
  146.   Code = xyDriver(ThePort)
  147.   If Code = XY_IDLE Then
  148.     'time to go to next XY state (since driver is idle)
  149.     Select Case xyState
  150.       '*** XYDRIVER states ***
  151.       Case TX_XM 'Send XMODEM
  152.         Code = xyStartTX(ThePort, TERM.AcceptText.Text, 0, XMODEM)
  153.         xyState = RUN_XY
  154.       Case RX_XM 'Receive XMODEM
  155.         Code = xyStartRX(ThePort, TERM.AcceptText.Text, NAK, XMODEM)
  156.         xyState = RUN_XY
  157. '''DisplayLine ("xyStartRX: Code=" + Str$(Code))
  158.       Case TX_YM 'Send YMODEM
  159.         Code = xyStartTX(ThePort, TERM.AcceptText.Text, 1, YMODEM)
  160.         xyState = RUN_XY
  161.       Case RX_YM 'Receive YMODEM
  162.         Code = xyStartRX(ThePort, TERM.AcceptText.Text, Asc("C"), YMODEM)
  163.         xyState = RUN_XY
  164.       Case RUN_XY 'XYDRIVER is done
  165.         Call DisplayLine(TERM, "xyDriver is done.")
  166.         xyState = 0
  167.         TERM.menuSend.Enabled = True
  168.         TERM.menuReceive.Enabled = True
  169.         TERM.menuBreak.Enabled = False
  170.     End Select
  171.   Else
  172.     'xyDriver is running
  173.     Packet = xyGetParameter(ThePort, XY_GET_PACKET)
  174.      If Packet <> LastPacket Then
  175.        Call DisplayLine(TERM, "Packet " + Str$(Packet))
  176.        LastPacket = Packet
  177.      End If
  178.    End If
  179. End Sub
  180.  
  181. Sub ShowConfig ()
  182.   Dim A As String
  183.   Dim B As String
  184.   Dim C As String
  185.   Dim D As String
  186.   Dim E As String
  187.   If OnLineFlag Then
  188.     A = " (Online)"
  189.   Else
  190.     A = " (Offline)"
  191.   End If
  192.   B = "COM" + LTrim$(Str$(ThePort + 1))
  193.   C = " @ " + BaudText(TheBaudCode) + " "
  194.   D = Str$(TheDataBits) + ParityText(TheParity)
  195.   E = LTrim$(Str$(1 + TheStopBits))
  196.   TERM.Caption = "TERM: " + B + C + D + E + A
  197. End Sub
  198.  
  199.